Spellhandler Reference Guide
This definitive guide covers every aspect of the spellhandling system in PAL, including object creation, properties, functions, and traits.
Table of Contents
- Spellhandler Namespace
- Spell Object Creation
- Spell Object Properties
- Utility Functions
- Spell Traits
- Spell Object Methods
Spellhandler Namespace
The spellhandler functionality is contained within the LT.spellhandling namespace.
LT.spellhandling = LT.spellhandling or {
spellbooks = {} ---@type table<string, table<string, Spell>>
}
The spellbooks table contains all the spellbooks for different classes, organized by class name.
Spell Object Creation
NewSpell(spellID, payload)
Creates a new spell object.
local spell = LT.spellhandling.NewSpell(12345, {
ignoreCasting = false,
ignoreChanneling = false,
ignoreCost = false,
ignoreFacing = false,
ignoreMoving = false,
isSkillshot = false,
maxOffset = 0,
minOffset = 0,
nextMelee = false,
radius = 0,
queued = false,
timeToHit = 0
})
This function creates a new Spell object with the given spell ID and optional payload. The payload can be used to set various properties of the spell object.
Spell Object Properties
These properties can be set when creating a new spell object or using the setPayload method:
spellID: The ID of the spell (required)ignoreCasting: If true, the spell can be cast while casting other spellsignoreChanneling: If true, the spell can be cast while channeling other spellsignoreCost: If true, the spell's resource cost is ignored when checking if it's castableignoreFacing: If true, the spell can be cast without facing the targetignoreMoving: If true, the spell can be cast while movingisSkillshot: If true, the spell is treated as a skillshot ability, affecting how it's castmaxOffset: Maximum offset for skillshot abilities, used in calculating the spell's trajectoryminOffset: Minimum offset for skillshot abilities, used in calculating the spell's trajectorynextMelee: If true, the spell is considered a melee ability, affecting range checksradius: The radius of effect for AoE spells, used in target selection and positioningqueued: If true, the spell can be queued for castingtimeToHit: The time it takes for the spell to hit the target after casting, used in predictive casting
Utility Functions
PopulateSpellbook(spells, class)
Populates the spellbook for a specific class with the provided spells.
LT.spellhandling.PopulateSpellbook({
ArcaneBlast = NewSpell(30451),
ArcaneMissiles = NewSpell(5143),
-- More spells...
}, "MAGE")
This function adds multiple spells to the spellbook for a specific class, making them easily accessible in rotations.
Spell Traits
These are properties that can be accessed directly on a spell object:
spellID: The unique identifier of the spellname: The name of the spellid: The numeric ID of the spell (same as spellID)icon: The icon ID of the spellminRange: The minimum range of the spellmaxRange: The maximum range of the spellbaseCastTime: The base cast time of the spell in millisecondsknown: A boolean indicating whether the player knows the spellcallback: The callback function associated with the spelllastCallbackString: A string representation of the last callback execution (used for debugging)
These traits are typically set when the spell object is created or updated, and provide quick access to basic spell information.
Example usage:
local spellName = spell.name
local spellId = spell.id
local spellIcon = spell.icon
local isKnown = spell.known
Spell Object Methods
Callback(function)
Sets a callback function for the spell.
spell:Callback(function(spell, unit, logic)
-- Spell casting logic here
end)
This method sets the callback function that will be executed when the spell is cast. The callback receives the spell object, the target unit, and an optional logic parameter.
Cast(unit)
Attempts to cast the spell on the specified unit.
if spell:Cast(target) then
-- Spell was successfully cast
end
This method checks if the spell is castable on the target and, if so, casts it. It returns true if the spell was successfully cast.
Castable(unit)
Checks if the spell can be cast on the specified unit.
if spell:Castable(target) then
-- Spell can be cast on the target
end
This method performs a series of checks to determine if the spell can be cast on the target, including range, line of sight, cooldown, and resource checks.
execute(unit, logic)
Executes the spell's callback function.
if spell:execute(target, "some_logic") then
-- Spell's callback was executed successfully
end
This method calls the spell's callback function with the specified unit and logic. It's used to implement custom casting behavior.
ready()
Checks if the spell is ready to be cast.
if spell:ready() then
-- Spell is ready to be cast
end
This method checks if the spell is usable and off cooldown.